package com.mayikt.service;

import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.Opcodes;

/**
 * @ClassName Test0015
 * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
 * @Version V1.0
 **/
public class Test0015 extends ClassLoader {
    public static void main(String[] args) {
        /**
         * -XX:MaxMetaspaceSize=8m -XX:-UseCompressedClassPointers
         */
        int j = 0;
        try {
            Test0015 test = new Test0015();
            for (int i = 0; i < 30000; i++, j++) {
                ClassWriter cw = new ClassWriter(0);
                // 通过字节码的技术 直接创建一个字节码 Class0
                cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC,
                        "Class" + i, null, "java/lang/Object", null);
                byte[] code = cw.toByteArray();
                test.defineClass("Class" + i, code, 0, code.length);
            }
        } finally {
            System.out.println(j);
        }
    }
}
